<?php

namespace Bundle\ModuleBundle;

use Symfony\Components\DependencyInjection\ContainerInterface;

class PluginsContainer
{
    private $_plugins = array();

    public function add(\Bundle\ModuleBundle\Interfaces\PluginDescriptionInterface $pluginDescription)
    {
        if($pluginDescription->boot())
        {
            if($this->has($pluginDescription->getName()))
            {
                throw new \Exception();
            }

            $this->_plugins[$pluginDescription->getName()] = $pluginDescription;
            
            foreach($pluginDescription->getAliases() as $alias)
            {
                $this->_plugins[$alias] = $pluginDescription;
            }
        }
    }

    public function get($name)
    {
        if($this->has($name))
        {
            return $this->_plugins[$name];
        }
        throw new \Exception();
    }

    public function has($name)
    {
        return \array_key_exists($name, $this->_plugins);
    }

}